<?php

namespace app\admin\model;

use think\Model;
use think\model\concern\SoftDelete;

class VideoLevel extends Model
{
    use SoftDelete;

    protected $autoWriteTimestamp = true;

    protected $pk = 'level_id';

    public static function getList()
    {
        $where = [];
        $limit = input('get.limit');
        $page = input('get.page');
        if ($search = input('get.level_title')) $where[] = ['level_title', 'like', "%" . $search . "%"];
        $list = self::order('level_id', 'desc')
            ->where($where)
            ->paginate($limit);
        foreach ($list as $k => $v) {
            $list[$k]['level_remark'] = $v['level_remark'] ?: '-';
        }
        return ['code' => 0, 'data' => $list->items(), 'extend' => ['count' => $list->total(), 'limit' => $limit, 'page' => $page]];
    }

    public static function checkExist($levelId, $levelTitle)
    {
        return self::where('level_id', '<>', $levelId)
            ->where('level_title', $levelTitle)
            ->find();
    }

    public static function getLevelAll()
    {
        return self::order('level_sort desc,level_id desc')
            ->field(['level_id', 'level_title'])
            ->where('level_status', '=', 1)
            ->select()
            ->toArray();
    }
}